<?php

$_this =& $this;

/* @var $_this View */
/* @var $form FormHelper */
/* @var $editForm EditFormHelper */
/* @var $html HtmlHelper */
/* @var $ehtml EHtmlHelper */
/* @var $javascript JavascriptHelper */
/* @var $jqax JqaxHelper */
/* @var $filterBlock FilterBlock */

?><?=$filterBlock->create('Filter', array('url'=>("/{$url_part}/")));?><?php
	$filterBlock->add(
        $form->label('searche', __d(null, 'searche_filter', true).': ', array('class'=>'filter')).
		$form->text('searche', false, array('size' => '17', 'label' => false))
	);
?><?=$filterBlock->end();?><?php

?><br /><?php

if (count($list->rows)) {

?><?=$this->renderElement('pagination', array('paging' => $list->pagination));?><?php

?><table class="table" cellpadding="0"><?php
?><thead><?php
    ?><tr><?php
        ?><th class="nw"><?php
            ?><?=$this->renderElement('sort_field', array('obj' => $list->order, 'field' => 'fullname', 'msg'=>'name', 'domain'=>$po_domain));?><?php
        ?></th><?php
        ?><th class="nw"><?php
            ?><?=$this->renderElement('sort_field', array('obj' => $list->order, 'field' => 'client', 'msg'=>'client_id', 'domain'=>$po_domain));?><?php
        ?></th><?php
        ?><th class="nw"><?php
            ?><?=$this->renderElement('sort_field', array('obj' => $list->order, 'field' => 'login', 'msg'=>'username', 'domain'=>$po_domain));?><?php
        ?></th><?php
        ?><th class="nw"><?php
            ?><?=$this->renderElement('sort_field', array('obj' => $list->order, 'field' => 'address', 'msg'=>'address', 'domain'=>$po_domain));?><?php
        ?></th><?php
        ?><th class="nw"><?php
            ?><?=$this->renderElement('sort_field', array('obj' => $list->order, 'field' => 'email', 'domain'=>$po_domain));?><?php
        ?></th><?php
        ?><th class="nw"><?php
            ?><?=$this->renderElement('sort_field', array('obj' => $list->order, 'field' => 'permissions', 'domain'=>$po_domain));?><?php
        ?></th><?php
        ?><th class="actions nw"></th><?php
    ?></tr><?php
?></thead><?php
?><tbody><?php

    $i = 0;
    foreach ($list->rows as $item) {
        $class = '';
    	if ($i++ % 2 != 0) {
    	    $sep = strlen($class) ? ' ' : '';
    		$class .= $sep.'altrow';
    	}
    	$class = strlen($class) ? ' class="'.$class.'"' : '';

        ?><tr <?=$class;?>><?php
        	?><td class="nw"><?php
                ?><?=$item[$modelName]['name'];?><?php
                if (!empty($item[$modelName]['phone'])) {
                    ?><br /><?php
                    ?><?=__d($po_domain, 'phone_short', true);?>: <?php
                    ?><?=$item[$modelName]['phone'];?><?php
                }
                if (!empty($item[$modelName]['cell_phone'])) {
                    ?><br /><?php
                    ?><?=__d($po_domain, 'mobile_phone_short', true);?>: <?php
                    ?><?=$item[$modelName]['cell_phone'];?><?php
                }
            ?></td><?php
            ?><td><?php
                ?><?=$item['Client']['name'];?><?php
            ?></td><?php
    		?><td class="nw"><?php
                ?><?=$item[$modelName]['username'];?><?php
                ?><br /><?php
                ?><?=$item[$modelName]['password'];?><?php
            ?></td><?php
    		?><td><?php
                if (!empty($item[$modelName]['address'])) {
                    ?><?=$item[$modelName]['address'];?><?php
                } else {
                    ?>…<?php
                }
            ?></td><?php
            ?><td class="nw"><?php
                ?><?=$item[$modelName]['email'];?><?php
            ?></td><?php
            ?><td class="nw"><?php
                if (!empty($item[$modelName]['permissions'])) {
                    $str = array();
                    foreach ($permissions_list as $k => $v) {
                        if (in_array($k, $item[$modelName]['permissions'])) {
                            $str[] = h($v);
                        }
                    }
                    ?><?=implode(',<br/>', $str);?><?php
                } else {
                    ?>—<?php
                }
            ?></td><?php
            ?><td class="actions nw"><?php
                ?><table class="sys_clear" cellpadding="0"><?php
                ?><tr class="sys_clear"><?php
                    ?><?=$ehtml->iconLink("edit", __d(null, $item[$modelName]['__allows']['update'] ? 'change' : 'view', true), "/{$url_part}/{$item[$modelName][$PKName]}/");?><?php
                    $inactive = !($item[$modelName]['__allows']['delete']);
                    $inactive_str = $inactive ? __d(null, 'deny', true) : false;
                    if (!$inactive) {
                        ?><?=$ehtml->iconLink("cancel", __d(null, 'delete', true), "/{$url_part}/{$item[$modelName][$PKName]}/delete", array('inactive' => $inactive_str,), __d($po_domain, 'confirm_del', true)." ".__d(null, "open_q1", true).$item[$modelName]['name'].__d(null, "close_q1", true)."?");?><?php
                    }
                ?></tr><?php
                ?></table><?php
            ?></td><?php
    	?></tr><?php
    }

?></tbody><?php
?></table><?php

?><?=$this->renderElement('pagination', array('paging' => $list->pagination));?><?php

} else {
    ?><span class="additional_msg"><?php
        ?><?=__d(null, 'List is empty', true);?><?php
        if (!empty($filter)) {
            ?> <?=__d(null, 'Try to change filter parameters.', true);?><?php

        }
    ?></span><?php
}

?>